import { addPostSkill, getSkillDetail, getSkillLable } from '@/services'
import { makeAutoObservable } from 'mobx'
import { ISkillAddItem, Iskill ,IInterviewDetail} from '@/utils/interface.d'

class Skill {
    constructor() {
        makeAutoObservable(this)
    }

    // 定义仓库的属性
    skillLable: Iskill[] = []

    InterviewData: IInterviewDetail[] = []

    // 定义新增岗位参数
    skillAddItem: ISkillAddItem = {
        "majorId": "",
        "name": "",
        "stationVersion": 1,
        "userName": "郭老师",
        "stationVersionId": "",
        "majorName": "",
        "stationLevelList": [
            {
                "describes": "123",
                "salaryList": [
                    5000,
                    20000
                ],
                "stationLevel": 1,
                "stationTask": "456",
                "level_name": "初级",
                "disabled": false
            },
            {
                "describes": "",
                "salaryList": [
                    12000,
                    20000
                ],
                "stationLevel": 2,
                "level_name": "中级",
                "stationTask": "",
                "disabled": false
            },
            {
                "describes": "",
                "salaryList": [
                    20000,
                    40000
                ],
                "stationLevel": 3,
                "stationTask": "",
                "level_name": "高级",
                "disabled": false
            }
        ]
    }

    // 定义仓库中的方法
    async getSkillLable() {
        let result = await getSkillLable();
        if (result.data) {
            this.skillLable = result.data;
        }
    }

    /**
     * 
     * @param params describes: "123"
majorId: "P0002"
name: "前端工程师"
salaryList: Proxy {0: 5000, 1: 20000, Symbol(mobx administration): ObservableArrayAdministration}
stationTask: "456"
stationVersion: 1
userName: ""
     */
    // 新增岗位
    async addPostSkill(params: ISkillAddItem) {
        let { describes, majorId, name, salaryList, stationTask, stationVersion } = params;
        let stationLevelList = this.skillAddItem.stationLevelList;
        stationLevelList[0] = { ...stationLevelList[0], salaryList: salaryList as number[], describes: describes as string, stationTask: stationTask as string };
        this.skillAddItem = { ...this.skillAddItem, majorId, name, stationVersion, stationLevelList };
        console.log('skillAddItem', this.skillAddItem);
        let result = await addPostSkill(this.skillAddItem);

        if (result.data) {
            this.skillAddItem = result.data;
            return result.data.stationVersionId;
        }
    }

    // 获取岗位详情
    async getSkillDetail(stationVersionId: string) {
        let result = await getSkillDetail(stationVersionId);

        if (result.data) {
            this.skillAddItem = result.data;
        }
    }

    // 获取面试详情
    // async getInterviewDetail(interviewId: string) {
    //     let result = await getInterviewDetail(interviewId);
        
    //     if (result.data) {
    //         console.log(result.data);
    //         this.InterviewData = result.data;
    //     if (result.data) {
    //         this.skillAddItem = result.data;
    //     }
    // }
}

export default new Skill